<template>
	<view class="content">
		<view class="section-0">
			<view class="section-body">
				<view>
					<view class="title">
						<view class="name">
							{{ title }}
						</view>
						<view class="time">
							{{ create_time ? create_time.substring(0, 10) : '-' }}
						</view>
					</view>
					<view class="stile">
						{{ msg }}
					</view>
				</view>
				<!-- <view class="button" v-show="is_read!==1">
					<button @click="later()">稍后提醒</button>
					<button @click="close()">已阅读</button>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import {
		UserMsgDetailApi,
		UserMsgReadApi,
		UserMsgListApi
	} from '@/api/statistics.js'
	export default {
		computed: {
			...mapGetters({
				userInfo: 'system/getUserInfo'
			})
		},
		data() {
			return {
				msg: '',
				title: '',
				create_time: '',
				id: '',
				is_read: ''
			}
		},
		methods: {
			// 弹框稍后再说
			// later() {
			// 	let obj={}
			// 	obj = {
			// 		uid:this.userInfo.user_id,
			// 		id: this.id,
			// 		status: 2,
			// 	}
			// 	UserMsgReadApi({...obj}).then(res=>{
			// 		if(res){
			// 			uni.navigateTo({
			// 				url: '/pages/statistics/mail/stationLetter'
			// 			})
			// 		}
			// 	})
			// },
			//  弹框已阅读
			close() {
				let obj = {}
				obj = {
					uid: this.userInfo.user_id,
					id: this.id,
					status: 1,
				}
				UserMsgReadApi({
					...obj
				}).then(res => {
					if (res) {
						UserMsgListApi({
							uid: this.userInfo.user_id,
							select_is_read: 0
						}).then(item => {
							// #ifdef APP-PLUS
							if (item.data.data.push == 1) {
								plus.push.clear()
								uni.getSystemInfo({
									success(list) {
										if (list.brand == 'Xiaomi') {
											plus.runtime.setBadgeNumber(item.data.data
												.total_unread - 1)
										} else {
											plus.runtime.setBadgeNumber(item.data.data
												.total_unread)
										}
									}
								})
							}
							// #endif
						})
					}

					// if(res){
					// 	uni.navigateTo({
					// 		url: '/pages/statistics/mail/stationLetter'
					// 	})
					// }
				})
			},
		},
		onLoad(e) {
			this.id = e.id
			UserMsgDetailApi({
				id: e.id
			}).then(res => {
				this.msg = res.data.data.msg
				this.title = res.data.data.title
				this.create_time = res.data.data.create_time
				this.is_read = res.data.data.is_read
				this.close()
			})
		},
		// onBackPress() {
		// 	uni.navigateTo({
		// 			url: '/pages/statistics/mail/stationLetter'
		// 		})
		// 		return true
		// }
	}
</script>

<style lang="scss" scoped>
	.custom-button {
		margin-top: 70rpx;
		box-shadow: 0rpx 13rpx 35rpx 0rpx rgba(60, 90, 214, 0.42);
	}

	.section-0 {
		width: 100%;
		background-color: #3a5df5;

		.section-body {
			padding-top: 50rpx;
			box-sizing: border-box;
			width: 100%;
			padding-left: 40rpx;
			padding-right: 40rpx;
			padding-bottom: 50rpx;
			background-color: #fff;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;

			.title {
				margin-bottom: 20rpx;

				.name {
					font-size: 40rpx;
					font-weight: bold;
					margin-bottom: 20rpx;
				}

				.time {
					font-size: 30rpx;
					color: #a4a4a4;
				}
			}

			.stile {
				font-size: 30rpx;
			}

			.button {
				// border-radius: 20rpx;
				width: 90vw;
				position: absolute;
				bottom: 10px;
				display: flex;

				button:first-child {
					width: 35vw;
					overflow: hidden;
				}

				button:nth-child(2) {
					width: 35vw;
					color: #ffffff;
					background-color: #1534ce;
					border-left: 1px solid #607cda;
				}
			}
		}
	}
</style>
